package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

func main() {

	fileNameList := getFileListFromDir("/Users/wangmaolin/Documents/yc/日报/")
	log.Println(fileNameList)
	if len(fileNameList) > 0 {
		readFile(fileNameList, "/Users/wangmaolin/Documents/yc/日报/all4/", "all.txt")
	}

}
func getFileListFromDir(dirName string) []string {
	dir, err := ioutil.ReadDir(dirName)
	if err != nil {
		fmt.Println(err)
	}
	fileNames := make([]string, len(dir))
	for i := range dir {
		if !dir[i].IsDir() {
			fileNames = append(fileNames, dirName+dir[i].Name())
		}
	}
	return fileNames
}
func readFile(fileList []string, targetDir string, targetFile string) {
	if len(fileList) > 0 {
		create, _ := os.Create(targetDir)

		for i := range fileList {
			log.Println("read file" + fileList[i])
			//open, _ := os.Open(fileList[i])
			file, err := ioutil.ReadFile(fileList[i])
			if err == nil {

				bytes := file
				_, _ = create.Write(bytes)
			} else {
				log.Println("read file " + fileList[i] + " error : " + err.Error())
			}

		}
	}
}
